package com.vctgo.demo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.demo.domain.AccountingCategories;
import com.vctgo.demo.service.IAccountingCategoriesService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 核算类别设置Controller
 *
 * @author vctgo
 * @date 2024-12-17
 */
@RestController
@RequestMapping("/categories")
public class AccountingCategoriesController extends BaseController
{
    @Autowired
    private IAccountingCategoriesService accountingCategoriesService;

    /**
     * 查询核算类别设置列表
     */
    @RequiresPermissions("demo:categories:list")
    @GetMapping("/list")
    public AjaxResult list(AccountingCategories accountingCategories)
    {
        IPage<AccountingCategories> list = accountingCategoriesService.selectAccountingCategoriesPage(accountingCategories);
        return AjaxResult.success(list);
    }

    /**
     * 导出核算类别设置列表
     */
    @RequiresPermissions("demo:categories:export")
    @Log(title = "核算类别设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccountingCategories accountingCategories)
    {
        List<AccountingCategories> list = accountingCategoriesService.selectAccountingCategoriesList(accountingCategories);
        ExcelUtil<AccountingCategories> util = new ExcelUtil<AccountingCategories>(AccountingCategories.class);
        util.exportExcel(response, list, "核算类别设置数据");
    }

    /**
     * 获取核算类别设置详细信息
     */
    @RequiresPermissions("demo:categories:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(accountingCategoriesService.selectAccountingCategoriesById(id));
    }

    /**
     * 新增核算类别设置
     */
    @RequiresPermissions("demo:categories:add")
    @Log(title = "核算类别设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AccountingCategories accountingCategories)
    {
        return toAjax(accountingCategoriesService.insertAccountingCategories(accountingCategories));
    }

    /**
     * 修改核算类别设置
     */
    @RequiresPermissions("demo:categories:edit")
    @Log(title = "核算类别设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AccountingCategories accountingCategories)
    {
        return toAjax(accountingCategoriesService.updateAccountingCategories(accountingCategories));
    }

    /**
     * 删除核算类别设置
     */
    @RequiresPermissions("demo:categories:remove")
    @Log(title = "核算类别设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(accountingCategoriesService.deleteAccountingCategoriesByIds(ids));
    }
}
